<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="user-scalable=no,width=device-width, initial-scale=1" id="viewport" name="viewport" initial-scale="1">
<meta name="renderer" content="webkit"/>
<meta name="force-rendering" content="webkit"/>
<script language="javascript" type="text/javascript" src="../js/js/baseJs.js"></script>

</head>
<body style="background: #3f97f2">

<div class="admin-login" id="adminLogin" style="display: none;">
  <div class="login-content"> 
    <div class="bl-bd"> 
      <div class="logo-bd"><img src="../image/logo.jpg">来赚吧后台管理</div>
      <div class="input-group"> 
      <div class="account">        
          <input  oninput="if(value.length>11)value=value.slice(0,11)" placeholder="手机账号" v-model="mobileNumber">
        </div>
        <div class="key"><input placeholder="密码" type="password" autocomplete="off" readonly onfocus="this.removeAttribute('readonly')" v-model="password" ></div>
      </div>
      <div class="comfirm-button" @click="loginAccount">确定</div>
    </div>
    
    
  </div>  
</div>
<script src="../js/js/common.js"></script>
<script type="text/javascript">
  // var token=getCookie("userToken");
  // console.log(token)
  // setCookie("userToken","111")
  // setCookie("userId","222")
var allUrl =window.location.href;
var dumpUrl=allUrl.split("?")[1];
console.log(dumpUrl)
  var wapLoginApp = new Vue({
      el: '#adminLogin',
      data: {
          mobileNumber : "",
          password:"",
          isloginingAccount:false
      },
      created:function(){
        $("#adminLogin").show();
     
      },
      methods:{
        isMobileNumberValid: function (phone) {
            //todo check this.mobileNumber is mobile
            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(phone)) {
                return false;
            } else {
                return true;
            }
        },
        loginAccount:function(){
            if(this.isloginingAccount){
              return;
            };
            if(!this.isMobileNumberValid(this.mobileNumber)){
              console.log(this.isMobileNumberValid(this.mobileNumber))
              alert("请输入正确的手机号")
              return;
            };
            if(!this.password){
              alert("请输入密码");
              return;
            }
            var url="/user/loginAdmin";
            var data={
               client:3,
               telephone: this.mobileNumber,
               password:this.password
             };
            pushData(url,data,function(res){
              console.log(res);
                this.isloginingAccount=false;
                if(res.state){
                  alert("登录成功")
                  setCookie("userToken",res.data.token);
                  setCookie("userId",res.data.user.id);
                  setCookie("invitationCode",res.data.user.invitationCode);                
                  if(dumpUrl){
                    window.location.href=dumpUrl;
                  }else{
                    window.location.href = "../admin/creatProduct.html"
                  }
                }else{
                  alert(res.message)
                }
            }.bind(this))

        }
        
      }
    })
</script>

</body>
</html>